# bbb = """009.proxy.不代理的地址列表.md
# 010.电影下载.md
# 011.文本编辑器Typora软件下载和安装教程兼容WIN10.md
# 012.WPS2019软件下载和安装教程.md
# 013.vscode设置.md
# 014.禁用谷歌浏览器自动更新最好的解决方式.md
# 015.windows下初始化git.md
# 016.windows下安装v2ray客户端.md
# 017.chrome代理工具ZeroOmega.md
# 018.NavicatPremium破解版激活详细教程注册机无需断网.md
# 019.ghost博客搭建.md
# 工具.md
# index.md"""

# for item in bbb.split("\n"):
#     print(f'{{ text: \'{item[:-3]}\', link: \'/windows/{item}\' }},')

# # "{ text: 'Getting Started', link: '/getting-started' }"

# kkk = """
# 001_编辑器.md
# 112.redis安装.md
# 113.redis知识之HyperLogLog.md
# 114.redis性能测试.md
# index.md
# """

# import os
# for item in kkk.splitlines():
#     ttt = f"[{os.path.basename(item)}](./{item})"
#     print(ttt)
#     print()


import os

# 指定目录路径
path = "../docs"

# 获取目录下所有文件和文件夹的列表
files = os.listdir(path)

sidebar_items = []
public_dir = ["zip",""]
# 遍历列表并打印
for file_name in files:
    if os.path.isdir(os.sep.join([path, file_name])):
        w1 = {"text": file_name, "collapsed": False, "items": []}
        # print(f"{file_name} is dir")
        files2 = os.listdir(os.sep.join([path, file_name]))
        items2 = []
        for file_name2 in files2:
            if file_name2.lower().endswith(".md"):
                file_name2 = file_name2[:-3]
                # print(file_name2)
                item = f"""{{text: file_name2, link: "/{file_name}/{file_name2}.md"}}"""
                items2.append(item)
                # print(item)
            w1["items"] = items2
        sidebar_items.append(w1)

    else:
        print(f"{file_name} is file")

print(sidebar_items)
# from pprint import pprint

# import json
# json.dumps(sidebar_items, indent=4, ensure_ascii=False)
# with open("./sidebar.json", "w") as f:
#     json.dump(sidebar_items, f, indent=4, ensure_ascii=False)
# # pprint(sidebar_items)


# import json
# import re

# with open("../docs/.vitepress/config.mts", "r", encoding="utf-8") as f:
#     content = f.read()
# pattern = "export default defineConfig\((.*)\)"
# t1 = re.findall(pattern, content,re.S)
# # t1 = re.findall("export default defineConfig(.*)", content,re.M)
# print(t1[0])


# t2 = json.loads(t1[0])
# print(t2)
# print(type(t1[0]))
# with open("demo.json", "w", encoding="utf-8") as f:
#     f.write(json.dumps(t1[0], indent=4, ensure_ascii=False))